package com.hksj.Intelligentmanagement.controller;

import com.hksj.Intelligentmanagement.common.Rest;
import com.hksj.Intelligentmanagement.common.Result;
import com.hksj.Intelligentmanagement.dto.DepartmentDTO;
import com.hksj.Intelligentmanagement.service.DepartmentService;
import com.hksj.Intelligentmanagement.vo.RoomVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "科室管理")
@RestController
@RequestMapping("/api/department")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    @ApiOperation(value = "科室新增")
    @PostMapping("/saveDepartment")
    public Result saveDepartment(@RequestBody DepartmentDTO departmentDTO) {

        return departmentService.saveDepartment(departmentDTO);
    }

    @ApiOperation(value = "科室删除")
    @GetMapping ("/delDepartment{id}")
    public Result delDepartment(@PathVariable("id") String id) {
        return  departmentService.delDepartment(id);
    }

    @ApiOperation("科室修改")
    @PostMapping("/updateDepartment")
    public Result updateDepartment(@RequestBody @Validated(DepartmentDTO.Update.class) DepartmentDTO departmentDTO) {
        return departmentService.updateDepartment(departmentDTO);
    }

    @ApiOperation(value = "通过id查询科室")
    @GetMapping("queryDepartmentId/{id}")
    public Result queryDepartmentId(@PathVariable("id") String id) {

        return departmentService.queryDepartmentId(id);
    }

    @ApiOperation(value = "根据区域信息查询科室列表")
    @PostMapping("queryDepartmentListByPage")
    public Result queryDepartmentListByPage(@RequestBody DepartmentDTO departmentDTO) {
        return Result.ok(departmentService.queryDepartmentListByPage(departmentDTO));
    }

    @ApiOperation(value = "根据区域id查询科室手术信息")
    @PostMapping("listRoomByRegionId")
    public Rest<List<RoomVo>> listRoomByRegionId(
        @ApiParam(value = "手术日期 yyyy-MM-dd",required = true) @RequestParam String time,
        @ApiParam(value = "区域id",required = true) @RequestParam String regionId,
        @ApiParam(value = "类型  1 = 护士  2 = 麻醉",required = false) @RequestParam(required = false) Integer type){
        List<RoomVo> roomList =  departmentService.listRoomByRegionId(regionId,time,type);
        return Rest.ok(roomList);
    }
}
